<script>
export default {
  onLaunch: function () {
    console.log('App Launch')
  },
  onShow: async function () {
    console.log('App Show')
    const token = uni.getStorageSync('token')
    const userInfo = uni.getStorageSync('userInfo')
    const timeStamp = parseInt(Date.now() / 1000)
    if (token && userInfo && timeStamp < userInfo.expiretime) this.getCartNumber()
  },
  onHide: function () {
    console.log('App Hide')
  },
  methods: {
    // 获取购物车数量
    async getCartNumber() {
      const res = await this.$http.post('/api/kuyou/order/index/getCartNumber', false)
      if (res.code == 200) {
        if (res.data === 0) {
          uni.removeTabBarBadge({ index: 2 })
        } else {
          uni.setTabBarBadge({
            index: 2,
            text: res.data + ''
          })
        }
      }
    }
  }
}
</script>

<style lang="scss">
/*每个页面公共css */
@import 'components/uview-ui/index.scss';
@import 'static/css/base.css';
@import 'static/iconfont/iconfont.css';
@import 'static/iconfont/iconfont-weapp-icon.css';
uni-swiper .uni-swiper-dot-active {
  width: 20px !important;
}

// 解决商品富文本图片宽度超出屏幕宽度的问题
.rich-text-img {
  width: 100% !important;
  height: 100% !important;
}
</style>

